package uit.minito.database;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import uit.minito.timduongxebuyt.StaticVariables;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

	/** The is run before. */
	public static boolean isRunBefore = false;

	/** The context. */
	Context context;
	public SQLiteDatabase myDataBase;
	// private String DB_PATH =
	// context.getApplicationContext().getPackageName()+"/databases/";
	private String DB_PATH;

	public DatabaseHelper(Context context, SQLiteDatabase _myDataBase) {
		super(context, DbDefines.DATABASE_NAME, null,
				DbDefines.DATABASE_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create all data tables
		if (!isRunBefore) {

			// createStationTable(db);
			createHistoryTable(db);
			isRunBefore = true;
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	private void createHistoryTable(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE " + DbDefines.HistoryTableName + " ("
				+ DbDefines.HistoryTable.historyID + " INTEGER,"
				+ DbDefines.HistoryTable.latitudeStart + " TEXT,"
				+ DbDefines.HistoryTable.longitudeStart + " TEXT,"
				+ DbDefines.HistoryTable.addressStart + " TEXT,"
				
				+ DbDefines.HistoryTable.latitudeEnd + " TEXT,"
				+ DbDefines.HistoryTable.longitudeEnd + " TEXT,"
				+ DbDefines.HistoryTable.addressEnd + " TEXT,"
				+ DbDefines.HistoryTable.routerDetails + " TEXT,"
				+ DbDefines.HistoryTable.numOfRouters + " INTEGER,"
				+ DbDefines.HistoryTable.timeSpent + " REAL,"
				+ DbDefines.HistoryTable.distance + " REAL,"
				
				+ DbDefines.HistoryTable.dateAdded + " DATETIME,"
				+ "PRIMARY KEY (" + DbDefines.HistoryTable.historyID + "))");
	}

}
